package com.woniuxy.cloud.ticket52.movieassembly.components;

import com.woniuxy.cloud.ticket52.common.exception.TicketException;
import com.woniuxy.cloud.ticket52.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(TicketException.class)
    @ResponseBody
    public Result handleTicketException(TicketException e) {
        log.error("出现业务异常:" + e.getMessage());
        return Result.fail("请联系管理员。错误提示：" + e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result handleException(Exception e) {
        log.error("出现异常:",e);
        return Result.fail("服务器开了个小差，程序员小哥正在努力修复，请稍等。错误提示：" + e.getMessage());
    }

}
